package hashtables.Entries;

/**
 * A distribution element
 * @author Konstantin, Jan
 */
public class HashtableDistributionEntry
{
    private int _entries;
    private int _count;
    
    /**
     * Creates a distribution element
     * @param entries Number of entries in a bucket
     */
    public HashtableDistributionEntry(int entries)
    {
        _entries = entries;
        _count = 1;
    }

    /**
     * Gets the number of entries
     * @return value The number of entries
     */
    public int getNumEntries()
    {
        return _entries;
    }

    /**
     * Gets the number of buckets with "_entries" entries
     * @return Count of entries
     */
    public int getCount()
    {
        return _count;
    }

    /**
     * Sets the count
     * @param value The new count
     */
    public void setCount(int value)
    {
        _count = value;
    }

    /**
     * Increments the count
     */
    public void incrementCount()
    {
        _count++;
    }
    
    /**
     * Overrides the toString
     * @return The distribution
     */
    @Override public String toString()
    {
        return String.format("%7d: %5d", _entries, _count);
    }

    /**
     * Overrides the hashCode
     * @return The hash
     */
    @Override public int hashCode()
    {
        return _entries;
    }
    
    /**
     * Overrides the equals
     * @return true if they are equal
     */
    @Override public boolean equals(Object that)
    {
        // Comparing with itself
        if (this == that)
        {
            return true;
        }
        
        // Not a HashtableDistributionEntry
        if (!(that instanceof HashtableDistributionEntry))
        {
            return false;
        }
    
        // Compare the number of entries
        return _entries == ((HashtableDistributionEntry)that).getNumEntries();
    }
}
